<?php

namespace App\Http\Controllers\Frontend;


use App\Logics\NewsLogic;
use App\Service\Rss;


class RssController extends BaseController
{


    // rss 初始化
    public function initialize()
    {
        // 这里是测试
        parent::initialize();
    }

    // rss
    public function index()
    {
        header('Content-Type: text/xml');

        $title  = "asia tech wire";
        $domain = "https://www.asiatechwire.com/";
        $desc   = "technology intelligence network,TMT, biomedicine, fintech, blockchain and investment";
        $myRss  = new Rss($title, $domain, $desc);


        $option = $this->optLogic();
        $option->setField('cate_id', 0);
        $option->setField('rows', 100);
        $option->setField('is_count', null);  // 不进行统计
        $option->setField('is_first', 1);  // 返回详情第一段
        $option->setField('title', null);  // 避免页面传值的时候进行搜索


        $logic  = new NewsLogic();
        $result = $logic->onLists();
        $lists  = $result['list'];

        if(count($lists)){
            foreach($lists as $k => $row){
                $url   = atwUrl('article', $row);
                $ctime = date("Y-m-d H:i:s", $row["ctime"]);

                $myRss->AddItem($row['en_title'], $url, $row['en_description'], $ctime, $row['pic']);
            }
        }

        /*$myRss->SaveToFile("rss.xml");
         $myRss->getFile("rss.xml");*/
        $myRss->BuildRSS();
        $result = $myRss->show();

        return response($result, 200)->header('Content-Type', 'text/xml');
    }


}


